<?php
/**
 * Created by PhpStorm.
 * User: fangwei
 * Date: 2019-07-03
 * Time: 22:44
 */

namespace App\Http\Controllers\Admin\Api;


use App\Http\Controllers\Controller;
use App\Http\Repositories\Services\ICompany;
use App\Http\Requests\Admin\CompanyInputDTO;
use App\Util\LayUiVo;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Lang;

class CompanyController extends Controller
{
    protected $companyService;

    public function __construct(ICompany $companyService)
    {
        $this->companyService = $companyService;
    }

    public function page(Request $request){
        $search = [];
        if ($request->get('title')) {
            $search['title'] = $request->get('title');
        }

        $dao = $this->companyService->lists($search, $request->get('page', 1), $request->get('limit','10'));
        return response()->json(new LayUiVo(['data'=>$dao,'message'=>Lang::get('response.success')]));
    }

    public function store(CompanyInputDTO $inputDTO){
        $this->companyService->store($inputDTO);
        return response()->json(new LayUiVo(['message'=>Lang::get('response.success')]));
    }

    public function update(CompanyInputDTO $inputDTO,$id){
        $this->companyService->update($inputDTO,$id);
        return response()->json(new LayUiVo(['message'=>Lang::get('response.success')]));
    }

    public function delete($id){
        $this->companyService->delete($id);
        return response()->json(new LayUiVo(['message'=>Lang::get('response.success')]));
    }
}